<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp_lib/init.jsp"%>

<script type="text/javascript">
	var add_form_panel;
	var add_form_panel_win;

	Ext.onReady(function() {

		add_form_panel = Ext.create("Ext.form.Panel", {
			url : "add.htm",
			buttonAlign : "center",
			bodyStyle : "padding: 10px;",
			defaultType : "textfield",
			items : [ {
				fieldLabel : "角色名 ",
				name : "role.name",
				allowBlank : false
			}, {
				fieldLabel : "权限",
				name : "role.auth_codes",
				hidden : true
			}, {
				xtype : "fieldcontainer",
				fieldLabel : "权限选择",
				layout : "hbox",
				items : [ treePanel ]
			} ],
			buttons : [ {
				text : "保存",
				formBind : true, //only enabled once the form is valid
				disabled : true,
				handler : function() {
					var form = this.up("form").getForm();

					//设置选择框
					var auth_codes = treePanel.getLeafIdSelections();

					form.setValues({
						"role.auth_codes" : auth_codes
					});

					if (form.isValid()) {
						form.submit({
							waitMsg : "保存中...",
							success : function(form, action) {
								Ext.Msg.alert("提示", action.result.tip.msg);
								add_form_panel_win.close();
								dataStore.load();
							},
							failure : function(form, action) {
								Ext.Msg.alert("提示", action.result.tip.msg);
							}
						});
					}
				}
			} ]
		});

		add_form_panel_win = Ext.create("Ext.Window", {
			title : "角色添加 ",
			closeAction : "hide",
			items : add_form_panel
		});
	});

	function myAdd() {
		add_form_panel.getForm().reset();
		treePanel.setSelections("");
		add_form_panel_win.show();
	}
</script>
